package cn.com.ejiakanghu.service;

import org.linlinjava.litemall.core.util.IpUtil;
import org.linlinjava.litemall.db.domain.AgedmallLogGoodsView;
import org.linlinjava.litemall.db.service.log.AgedmallLogGoodsViewService;
import org.linlinjava.litemall.db.vo.app.StoreGoodsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * 日志管理
 * @author houzb
 * @Description
 * @create 2021-12-10 11:32
 */
@Service
public class LogManager {

    @Autowired
    private AgedmallLogGoodsViewService agedmallLogGoodsViewService;

    /**
     * 记录商品浏览日志
     * @param uid
     * @param info
     */
    public void recordGoodsViewLog(Integer uid,  StoreGoodsVo info) {
        if(info == null) {
            return;
        }
        String uip = IpUtil.getReqUserIp();
        AgedmallLogGoodsView goodsView = new AgedmallLogGoodsView();
        goodsView.setGoodsId(info.getId());
        goodsView.setGoodsType(info.getGoodsType());
        goodsView.setStoreGoodsId(info.getStoreGoodsId());
        goodsView.setViewDate(LocalDate.now());
        goodsView.setUid(uid == null ? 0 : Long.valueOf(uid));
        goodsView.setUip(uip);
        goodsView.setProductType("goods");
        goodsView.setCreated(LocalDateTime.now());
        agedmallLogGoodsViewService.recordGoodsView(goodsView);
    }

}
